package com.trkj.dao.jpa;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.trkj.pojos.YzrMedDraw;

public interface IYzrMedDrawDAO extends CrudRepository<YzrMedDraw, String> {

	@Query("select max(ymd.medDrawId) from YzrMedDraw ymd where ymd.medDrawId like ?1%")
	public String findMaxId(String a);
	
	@Query("select ymd from YzrMedDraw ymd order by ymd.medDrawId desc")
	public List<YzrMedDraw> findAllDraw(Pageable pageable);
	
	//id
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawId=?1  order by ymd.medDrawId desc")
	public List<YzrMedDraw> findByDraw(String name, Pageable pageable);
	
	//zdr
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawPickPerson=?1  order by ymd.medDrawId desc")
	public List<YzrMedDraw> findByZdr(BigDecimal name, Pageable pageable);
	
	//spr
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawAutdit=?1  order by ymd.medDrawId desc")
	public List<YzrMedDraw> findBySpr(BigDecimal name, Pageable pageable);
	
	//tlr
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawDrawPerson=?1  order by ymd.medDrawId desc")
	public List<YzrMedDraw> findByTlr(BigDecimal name, Pageable pageable);
	
	//spzt
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawAutditState=?1  order by ymd.medDrawId desc")
	public List<YzrMedDraw> findBySpzt(String name, Pageable pageable);
	
	//tlzt
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawDrawState=?1  order by ymd.medDrawId desc")
	public List<YzrMedDraw> findByTlzt(String name, Pageable pageable);

	//时间段查询
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawDrawTime  between ?1 and ?2 order by ymd.medDrawId desc")
	public List<YzrMedDraw> findDrawByTime(Date startDate,Date endDate, Pageable pageable);
	
	//根据当前登录用户查询出待审批的提领单
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawAutdit=?1 and ymd.medDrawAutditState='待审批' order by ymd.medDrawId desc")
	public List<YzrMedDraw> findDrawByStaffId(BigDecimal staffId, Pageable pageable);
	
	//查询出‘未提领’且审批‘已通过’的提领单
	@Query("select ymd from YzrMedDraw ymd where ymd.medDrawDrawState='未提领' and ymd.medDrawAutditState='已通过' order by ymd.medDrawId desc")
	public List<YzrMedDraw> findDrawByDrawState();
}
